package com.bt.lms.service.impl;

import com.bt.lms.constant.BOConstant;
import com.bt.lms.entity.EnrollmentPlan;

import com.bt.lms.entity.page.Page;
import com.bt.lms.bo.EnrollmentList;
import com.bt.lms.dao.servise.EnrollmentPlanDao;
import com.bt.lms.dao.servise.impl.EnrollmentPlanDaoImpl;
import com.bt.lms.service.EnrollmentPlanService;

/**
 * 招生计划服务类
 *
 * @author 李鹏
 */
public class EnrollmentPlanServiceImpl implements EnrollmentPlanService {

    @Override
    public Page<EnrollmentList> pagingConditionQuery(Page<EnrollmentList> page,Page<EnrollmentPlan> enrollmentPlanPage) {

        //招生计划sql
        String sql = "select * from enp_plan limit ?,?"; //第几页，几条数据
        //招生计划dao
        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.pagingConditionQuery(sql, page,enrollmentPlanPage);

        return null;
    }

    @Override
    public boolean add(EnrollmentPlan enrollmentPlan) throws Exception {

        //招生计划表
        String sql = "insert into enp_plan(enp_plan_code,plan_name,plan_content,enp_level,enp_major,enp_population,tuition_standard,enp_start_time,enp_stop_time,req_mode," +
                "enp_place,contact,phone,email,enp_item,graduate_related_matters,replenish_explain,teach_plan_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.insert(sql, enrollmentPlan);

        //招生材料表
        String sql1 = ("insert enp_plan_registration_type(enp_plan_id,type) values(?,?)");
        enrollmentPlanDao.insertReg(sql1, enrollmentPlan);

        return true;

    }

    @Override

    public EnrollmentPlan detail(Long id,Long teachPlanId) throws Exception {

        //招生计划表
        String sql = "select * from enp_plan where id = ?";
        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.select(sql, id);

        //招生计划材料表
        String sql1 = "select type from enp_plan_registration_type where enp_plan_id= ?";
        enrollmentPlanDao.selectRegType(sql1, id);

        //教学计划名称
        EnrollmentPlan enrollmentPlan = new EnrollmentPlan();
        String sql2 = "select teach_plan_name from teach_plan where teach_plan_id = ?";
        enrollmentPlanDao.selectTeachPlanName(sql2, teachPlanId);

        return enrollmentPlan;
    }

    @Override
    public boolean edit(Long id, EnrollmentPlan enrollmentPlan) throws Exception {

        //招生计划表
        String sql = "update enp_plan set enp_plan_code = ?,plan_name = ?,plan_content = ?,enp_level = ?,enp_major = ?,enp_population = ?,tuition_standard = ?,enp_start_time = ?,enp_stop_time = ?,req_mode = ?,enp_place = ?,contact = ?,phone = ? ,email = ?,enp_item = ?,graduate_related_matters = ?,replenish_explain = ?,teach_plan_id = ? where id = ?" ;

        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.update(sql, id, enrollmentPlan);

        //招生材料表
        String sql1 = ("update enp_plan_registration_type set type = ? where enp_plan_id = ?");
        enrollmentPlanDao.updateReg(sql1, id, enrollmentPlan);

        return false;
    }

    @Override
    public boolean start(Long id) throws Exception {

        //sql语句
        String sql = "update enp_plan set status = " + BOConstant.ENROLLMENT_PLAN_START_STATUS_START + " where id = ?";
        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.updateStart(sql, id);

        return false;
    }

    @Override
    public boolean stop(Long id) throws Exception {

        //sql语句
        String sql = "update enp_plan set status = " + BOConstant.ENROLLMENT_PLAN_START_STATUS_STOP + " where id = ?";
        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.updateStop(sql, id);

        return false;
    }

    @Override
    public boolean delete(Long id) throws Exception {

        //sql语句
        String sql = "update enp_plan set deleted = " + BOConstant.DELETED_TRUE + " where id = ?";
        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.delete(sql, id);

        return false;
    }

    @Override
    public boolean finish(Long id) throws Exception {

        //sql语句
        String sql = "update enp_plan set status = " + BOConstant.ENROLLMENT_PLAN_STATUS_FINISH + " where id = ?";
        EnrollmentPlanDao enrollmentPlanDao = new EnrollmentPlanDaoImpl();
        enrollmentPlanDao.updateFinish(sql, id);

        return false;
    }
}
